package com.oceanread.cn.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.oceanread.cn.entity.Query;
import com.oceanread.cn.entity.Treelist1;
import com.oceanread.cn.entity.Treelist2;
import com.oceanread.cn.entity.Turbine;
import com.oceanread.cn.service.ITreelist1Service;
import com.oceanread.cn.service.ITreelist2Service;
import com.oceanread.cn.service.ITurbineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/Faninfo")
@CrossOrigin()
@Api(value = "风机Faninfo", tags = {"4.2-风机信息"})
public class TurbineController {

    @Autowired
    private ITurbineService iTurbineService;

    @ApiIgnore(value = "获取总表____前端可能有用")
    @GetMapping("/getall")
    public List<Turbine> getList() {
        return iTurbineService.getall();
    }

    @ApiOperation(value = "前端可视化 获取风机")
    @GetMapping("/getTurbine/{PrjCode}")
    public List<Turbine> getTurbine(@PathVariable("PrjCode") String PrjCode) {
        return iTurbineService.equal("PrjCode",PrjCode);
    }
    @ApiOperation(value = "风机信息____分页")
    @GetMapping("/getList")
    public JSONObject getList(@RequestParam(name = "page", required = true, defaultValue = "1") int page,
                              @RequestParam(name = "size", required = true, defaultValue = "10") int size) {
        JSONObject object = new JSONObject();
        object.put("data", iTurbineService.getTablelist(page, size));
        object.put("total", iTurbineService.getnum());
        return object;
    }

    @ApiOperation(value = "模糊查询____1参数+分页")
    @GetMapping("/query1")
    public JSONObject query(
            @RequestParam(name = "page", required = true, defaultValue = "1") int page,
            @RequestParam(name = "size", required = true, defaultValue = "10") int size,
            @RequestParam(name = "key", defaultValue = "PrjCode") String key,
            @RequestParam(name = "value", defaultValue = "1") String value
    ) {
        JSONObject object = new JSONObject();
        object.put("data", iTurbineService.query(page, size, key, value));
        object.put("total", iTurbineService.getnumquery(key, value));
        return object;
    }

    @ApiOperation(value = "精确查询____1参数+分页")
    @GetMapping("/queryEqual")
    public JSONObject queryEqual(
            @RequestParam(name = "page", required = true, defaultValue = "1") int page,
            @RequestParam(name = "size", required = true, defaultValue = "10") int size,
            @RequestParam(name = "key", defaultValue = "PrjCode") String key,
            @RequestParam(name = "value", defaultValue = "1") String value
    ) {
        JSONObject object = new JSONObject();
        object.put("data", iTurbineService.queryEqual(page, size, key, value));
        object.put("total", iTurbineService.getnumqueryEqual(key, value));
        return object;
    }

    @ApiOperation(value = "更新")
    @PostMapping("/update")
    public Integer update(@RequestBody Turbine turbine) {
        return iTurbineService.update(turbine);
    }

    @ApiOperation(value = "插入")
    @PostMapping("/insert")
    public Integer insert(@RequestBody Turbine turbine) {
        System.out.println(turbine);
        return iTurbineService.insert(turbine.getPrjCode(), turbine.getName(), turbine.getID(), turbine.getLat(),
                turbine.getLon(), turbine.getStatus(), turbine.getSpeed(), turbine.getPower());
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public Integer delete(@RequestParam(name = "SYSID") int sysid) {
        return iTurbineService.delete(sysid);
    }
}
